home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / vm / vmStubs.c < prev    next >
C/C++ Source or Header  |  1991-07-26  |  6KB  |  294 lines

  1. /* 
  2.  * vmStubs.c --
  3.  *
  4.  *    Stubs for Unix compatible system calls.
  5.  *
  6.  * Copyright 1990 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: /sprite/src/kernel/vm/RCS/vmStubs.c,v 1.3 91/07/26 17:05:21 shirriff Exp $";
  18. #endif /* not lint */
  19.  
  20. #define MACH_UNIX_COMPAT
  21.  
  22. #include <sprite.h>
  23. #include <stdio.h>
  24. #include <status.h>
  25. #include <errno.h>
  26. #include <user/sys/types.h>
  27. #include <user/sys/mman.h>
  28. #include <mach.h>
  29. #include <proc.h>
  30. #include <timer.h>
  31. #include <vm.h>
  32. #include <vmInt.h>
  33. #include <vmUnixStubs.h>
  34.  
  35. int debugVmStubs;
  36.  
  37.  
  38. /*
  39.  *----------------------------------------------------------------------
  40.  *
  41.  * Vm_SbrkStub --
  42.  *
  43.  *    The stub for the "sbrk" Unix system call.
  44.  *
  45.  * Results:
  46.  *    Returns old break on success.
  47.  *    Returns -1 and errno on failure.
  48.  *
  49.  * Side effects:
  50.  *    Side effects associated with the system call.
  51.  *     
  52.  *
  53.  *----------------------------------------------------------------------
  54.  */
  55. int
  56. Vm_SbrkStub(addr)
  57.     Address    addr;
  58. {
  59.     Vm_Segment            *segPtr;
  60.     Address            lastAddr;
  61.     Proc_ControlBlock    *procPtr;
  62.  
  63.     if (debugVmStubs) {
  64.     printf("Vm_SbrkStub(0x%x)\n", addr);
  65.     }
  66.  
  67.     /*
  68.      * The UNIX brk and sbrk call stubs figure where the end of the
  69.      * heap is and they always call us with the new end of data segment.
  70.      */
  71.     procPtr = Proc_GetCurrentProc();
  72.     segPtr = procPtr->vmPtr->segPtrArray[VM_HEAP];
  73.     if (segPtr != (Vm_Segment *)NIL) {
  74.     lastAddr =
  75.         (Address) ((segPtr->offset + segPtr->numPages) * vm_PageSize);
  76.     if (Vm_CreateVA(lastAddr, addr - lastAddr) == SUCCESS) {
  77.  
  78.         if (debugVmStubs) {
  79.         printf("Vm_SbrkStub addr = %x, lastAddr = %x, newAddr = %x\n",
  80.             addr, lastAddr,
  81.             (segPtr->offset + segPtr->numPages) * vm_PageSize);
  82.         }
  83.         return 0;
  84.     }
  85.     }
  86.  
  87.     if (debugVmStubs) {
  88.     printf("Vm_SbrkStub Failed\n", addr);
  89.     }
  90.  
  91.     Mach_SetErrno(ENOMEM);
  92.     return -1;
  93. }
  94.  
  95.  
  96. /*
  97.  *----------------------------------------------------------------------
  98.  *
  99.  * Vm_GetpagesizeStub --
  100.  *
  101.  *    The stub for the "getpagesize" Unix system call.
  102.  *
  103.  * Results:
  104.  *    Returns -1 on failure.
  105.  *
  106.  * Side effects:
  107.  *    Side effects associated with the system call.
  108.  *     
  109.  *
  110.  *----------------------------------------------------------------------
  111.  */
  112. int
  113. Vm_GetpagesizeStub()
  114. {
  115.  
  116.     if (debugVmStubs) {
  117.     printf("Vm_GetpagesizeStub\n");
  118.     }
  119.     return vm_PageSize;
  120. }
  121.  
  122. #define _MAP_NEW 0x80000000 /* SunOS new mode mmap flag */
  123.  
  124.  
  125. /*
  126.  *----------------------------------------------------------------------
  127.  *
  128.  * Vm_MmapStub --
  129.  *
  130.  *    The stub for the "mmap" Unix system call.
  131.  *
  132.  * Results:
  133.  *    Returns -1 on failure.
  134.  *
  135.  * Side effects:
  136.  *    Side effects associated with the system call.
  137.  *     
  138.  *
  139.  *----------------------------------------------------------------------
  140.  */
  141. int
  142. Vm_MmapStub(addr, len, prot, share, fd, pos)
  143.     caddr_t    addr;
  144.     int    len, prot, share, fd;
  145.     off_t    pos;
  146. {
  147.     ReturnStatus    status;
  148.     Address        mappedAddr;
  149.     int            spriteProt=0;
  150.  
  151.     if (debugVmStubs) {
  152.     printf("Vm_MmapStub(%x, %x, %x, %x, %x, %x)\n", addr, len, prot,
  153.         share, fd, pos);
  154.     }
  155.  
  156.     if (prot&SUN_PROT_READ) {
  157.     spriteProt |= PROT_READ;
  158.     }
  159.     if (prot&SUN_PROT_WRITE) {
  160.     spriteProt |= PROT_WRITE;
  161.     }
  162.     if (prot&SUN_PROT_EXEC) {
  163.     spriteProt |= PROT_EXEC;
  164.     }
  165.     status = Vm_MmapInt(addr, len, spriteProt, share&~_MAP_NEW, fd, pos,
  166.         &mappedAddr);
  167.     if (status == SUCCESS) {
  168. #if defined(ds3100) || defined(ds5000)
  169.         return (int)mappedAddr;
  170. #else
  171.     if (debugVmStubs) {
  172.         printf("Vm_MmapStub: returns %x\n", mappedAddr);
  173.     }
  174.         if (share & _MAP_NEW) {
  175.         return (int)mappedAddr;
  176.     } else {
  177.         return 0;
  178.     }
  179. #endif
  180.     } else {
  181.     Mach_SetErrno(Compat_MapCode(status));
  182.     return -1;
  183.     }
  184. }
  185.  
  186.  
  187. /*
  188.  *----------------------------------------------------------------------
  189.  *
  190.  * Vm_MunmapStub --
  191.  *
  192.  *    The stub for the "munmap" Unix system call.
  193.  *
  194.  * Results:
  195.  *    Returns -1 on failure.
  196.  *
  197.  * Side effects:
  198.  *    Side effects associated with the system call.
  199.  *     
  200.  *
  201.  *----------------------------------------------------------------------
  202.  */
  203. int
  204. Vm_MunmapStub(addr, len)
  205.     caddr_t    addr;
  206.     int    len;
  207. {
  208.     ReturnStatus    status;
  209.  
  210.     if (debugVmStubs) {
  211.     printf("Vm_MunmapStub(%x, %x)\n", addr, len);
  212.     }
  213.     status = Vm_Munmap(addr, len, 0);
  214.     if (status == SUCCESS) {
  215.     return 0;
  216.     } else {
  217.     Mach_SetErrno(Compat_MapCode(status));
  218.     return -1;
  219.     }
  220. }
  221.  
  222.  
  223. /*
  224.  *----------------------------------------------------------------------
  225.  *
  226.  * Vm_MincoreStub --
  227.  *
  228.  *    The stub for the "mincore" Unix system call.
  229.  *
  230.  * Results:
  231.  *    Returns -1 on failure.
  232.  *
  233.  * Side effects:
  234.  *    Side effects associated with the system call.
  235.  *     
  236.  *
  237.  *----------------------------------------------------------------------
  238.  */
  239. int
  240. Vm_MincoreStub(addr, len, vec)
  241.     caddr_t    addr;
  242.     int len;
  243.     char vec[];
  244. {
  245.     ReturnStatus    status;
  246.  
  247.     if (debugVmStubs) {
  248.     printf("Vm_MincoreStub(%x, %x, %x)\n", addr, len, vec);
  249.     }
  250.     status = Vm_Mincore(addr, len, vec);
  251.     if (status == SUCCESS) {
  252.     return 0;
  253.     } else {
  254.     Mach_SetErrno(Compat_MapCode(status));
  255.     return -1;
  256.     }
  257. }
  258.  
  259. /*
  260.  *----------------------------------------------------------------------
  261.  *
  262.  * Vm_MprotectStub --
  263.  *
  264.  *    The stub for the "mprotect" Unix system call.
  265.  *
  266.  * Results:
  267.  *    Returns -1 on failure.
  268.  *
  269.  * Side effects:
  270.  *    Side effects associated with the system call.
  271.  *     
  272.  *
  273.  *----------------------------------------------------------------------
  274.  */
  275. int
  276. Vm_MprotectStub(addr, len, prot)
  277.     caddr_t    addr;
  278.     int len;
  279.     int prot;
  280. {
  281.     ReturnStatus    status;
  282.  
  283.     if (debugVmStubs) {
  284.     printf("Vm_MprotectStub(%x, %x, %x)\n", addr, len, prot);
  285.     }
  286.     status = Vm_Mprotect(addr, len, prot);
  287.     if (status == SUCCESS) {
  288.     return 0;
  289.     } else {
  290.     Mach_SetErrno(Compat_MapCode(status));
  291.     return -1;
  292.     }
  293. }
  294.